﻿using System;
using System.ComponentModel.DataAnnotations;
using System.Web.DynamicData;
using System.Web.Services;
using CDOP.Model;

namespace CDOP
{
    public partial class _Default : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
                if (Session["LoggedUser"] != null)
                {
                    var user = (UserDetails) Session["LoggedUser"];
                    if (user.UserType.Type.ToLower() != "admin")
                        Response.Redirect("Home.aspx");
                }
                else
                {
                    Response.Redirect("Login.aspx");
                }

            System.Collections.IList visibleTables = Global.DefaultModel.VisibleTables;
            if (visibleTables.Count == 0)
            {
                throw new InvalidOperationException("There are no accessible tables. Make sure that at least one data model is registered in Global.asax and scaffolding is enabled or implement custom pages.");
            }
            Menu1.DataSource = visibleTables;
            Menu1.DataBind();
        }

        [WebMethod]
        public static string IsCdopReferenceAvailable(string val)
        {
            System.Net.ServicePointManager.Expect100Continue = false;
            var isAvailable = new MasterTable().IsCdopReferenceAvailable(val);
            return isAvailable.ToString();
        }

    }
}
